package com.estun.backroundManagementService.domain;

import lombok.Data;

@Data
public class BaseResponse<T> {

    private static final Integer SUCCESS_CODE = 200;
    private static final String SUCCESS_MESSAGE = "success";

    private Integer code;

    private String message;

    private T data;

    private BaseResponse() {
    }

    public BaseResponse(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static BaseResponse error(String errorMessage) {
        return new BaseResponse<>(500, errorMessage, null);
    }

    public static BaseResponse error() {
        return null;
    }

    public static BaseResponse success() {
        return new BaseResponse(SUCCESS_CODE, SUCCESS_MESSAGE, null);
    }

    public static BaseResponse success(Object data) {
        return new BaseResponse(SUCCESS_CODE, SUCCESS_MESSAGE, data);
    }

    public static BaseResponse error(int code, String errorMessage) {
        return new BaseResponse<>(code, errorMessage, null);
    }

    public Boolean isSuccess() {
        return SUCCESS_CODE.equals(this.code);
    }

    public Boolean isFail() {
        return !SUCCESS_CODE.equals(this.code);
    }
}
